package utils

import (
	"errors"
	"reflect"
)

func Call(m map[string]interface{}, name string, params ...interface{}) ([]reflect.Value, error) {
	if h, ok := m[name]; ok {
		f := reflect.ValueOf(h)
		if len(params) != f.Type().NumIn() {
			err := errors.New("utils.Call: the number of params is not adapted")
			return nil, err
		}

		in := make([]reflect.Value, len(params))
		for k, param := range params {
			in[k] = reflect.ValueOf(param)
		}

		return f.Call(in), nil

	}
	return nil, nil
}
